# -- coding: utf-8 --
from wnboss05.tools.ui import UI
from wnboss05.tools.util import FileParser, DBParser

class TestCase:

    @classmethod
    def setupClass(cls):
        pass

    def setup(self):
        pass

    def teardown(self):
        pass

    @classmethod
    def teardownClass(cls):
        pass

    @classmethod
    def assert_equal(cls, data, actual):
        """
        断言相等
        :param expect:期望结果
        :param actual: 实际结果
        :return: None
        """
        # 写入数据库操作
        version = FileParser.read_excel('../data/ai.xls', 'info').cell(1, 1).value
        function = data['function']
        type = data['type']
        caseid = data['caseid']
        desc = data['desc']
        test_data = data['data']
        expect = data['expect']
        if expect == actual:
            result = 'test pass'
            png_path = ''
        else:
            result = 'test fail'
            if type == 'ui':
                png_path = UI.screenshot(version)
            else:
                png_path = ''

        sql = f'INSERT INTO woniuboss(`version`,`function`,`type`, ' \
              f'`caseid`, `desc`, `data`, `expect`,`actual`, `result`,`error_msg`, `png_path`) ' \
              f'values("{version}", "{function}", "{type}", "{caseid}", ' \
              f'"{desc}", "{test_data}", "{expect}", "{actual}","{result}", "", "{png_path}")'
        DBParser.update('testresult', sql)



if __name__ == '__main__':

    tc = TestCase()
    data = {'caseid': 'pr_add_002', 'function': '添加设备', 'type': 'ui', 'desc': '输入10位barcode数据，其它输入合法值，添加失败',
            'data': {'barcode': 'abc06885968', 'price': '100', 'employee': '孔银花', 'note': '公司的设备'},'expect': '添加失败'}
    UI.get_driver('Browser')
    UI.get('http://192.168.44.128:8080/WoniuBoss4.0')
    tc.assert_equal(data,'添加失败')